1
|
|
|
/** global: UB */ |
2
|
|
|
|
3
|
|
|
var stringFuncs = { |
4
|
|
|
|
5
|
|
|
insertAfterNth(find, insert, nth = 1, caseSensitive = true, wholeWords = false) { |
6
|
|
|
var text = this.toString(); |
7
|
|
|
var index = text.indexOfNth(find, nth, wholeWords, caseSensitive); |
8
|
|
|
if (index > -1) { |
9
|
|
|
return text.insertAt(insert, index + find.Length); |
10
|
|
|
} |
11
|
|
|
return text; |
12
|
|
|
}, |
13
|
|
|
insertAfterLast(find, insert, caseSensitive = true, wholeWords = false) { |
14
|
|
|
var text = this.toString(); |
15
|
|
|
return text.insertAfterNth(find, insert, 1, true, caseSensitive, wholeWords); |
16
|
|
|
}, |
17
|
|
|
insertAfterFirst(find, insert, caseSensitive = true, wholeWords = false) { |
18
|
|
|
var text = this.toString(); |
19
|
|
|
return text.insertAfterNth(find, insert, 1, false, caseSensitive, wholeWords); |
20
|
|
|
}, |
21
|
|
|
|
22
|
|
|
insertBeforeNth(find, insert, nth = 1, caseSensitive = true, wholeWords = false) { |
23
|
|
|
var text = this.toString(); |
24
|
|
|
var index = text.indexOfNth(find, nth, wholeWords, caseSensitive); |
25
|
|
|
if (index > -1) { |
26
|
|
|
return text.insertAt(insert, index); |
27
|
|
|
} |
28
|
|
|
return text; |
29
|
|
|
}, |
30
|
|
|
insertBeforeLast(find, insert, caseSensitive = true, wholeWords = false) { |
31
|
|
|
var text = this.toString(); |
32
|
|
|
return text.insertBeforeNth(find, insert, 1, true, caseSensitive, wholeWords); |
33
|
|
|
}, |
34
|
|
|
insertBeforeFirst(find, insert, caseSensitive = true, wholeWords = false) { |
35
|
|
|
var text = this.toString(); |
36
|
|
|
return text.insertBeforeNth(find, insert, 1, false, caseSensitive, wholeWords); |
37
|
|
|
}, |
38
|
|
|
|
39
|
|
|
none:null |
40
|
|
|
}; |
41
|
|
|
|
42
|
|
|
// register funcs |
43
|
|
|
UB.registerFuncs(String.prototype, stringFuncs); |